package com.lucenten.collect.gnss.controller;

import cn.quevo.common.annotation.RequiresPermissions;
import cn.quevo.common.entity.ResultEntity;
import cn.quevo.common.enums.ResultStatusEnum;
import cn.quevo.common.lang.StringUtils;
import cn.quevo.core.spring.SpringController;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import com.lucenten.collect.gnss.entity.ObsErvation;
import com.lucenten.collect.gnss.entity.query.ObsErvationQuery;
import com.lucenten.collect.gnss.service.ObsErvationService;

import java.util.Map;

/**
 * O文件实时统计信息 RestController
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2019/04/28 22:22:41
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@Api(value="O文件实时统计信息", tags = "O文件实时统计信息")
@RestController("obsErvationController")
@RequestMapping("/collect/")
public class ObsErvationRestController extends SpringController{

    @Resource(name="obsErvationService")
    private ObsErvationService obsErvationService;

    /**
     * 分页加载O文件实时统计信息
     *
     * @param obsErvationQuery
     * @return
     * @author July july_sky@foxmail.com
     * @date 2019/04/28 22:22:41
     */
    @ApiOperation(value = "分页加载O文件实时统计信息", notes = "")
    @GetMapping(value="obsErvation")
    @RequiresPermissions("collect:obsErvation:list")
    public ResultEntity page(ObsErvationQuery obsErvationQuery){
        return obsErvationService.getPage(obsErvationQuery);
    }

    /**
     * 保存O文件实时统计信息
     *
     * @param obsErvation
     * @return
     * @author July july_sky@foxmail.com
     * @date 2019/04/28 22:22:41
     */
    @ApiOperation(value = "保存O文件实时统计信息", notes = "")
    @PostMapping(value="obsErvation")
    @RequiresPermissions("collect:obsErvation:create")
    public ResultEntity create(@RequestBody ObsErvation obsErvation){
        if(obsErvationService.create(obsErvation) <= 0){
            return new ResultEntity(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }

    /**
     * 修改O文件实时统计信息
     *
     * @param obsErvation
     * @param id
     * @return
     * @author July july_sky@foxmail.com
     * @date 2019/04/28 22:22:41
     */
    @ApiOperation(value = "修改O文件实时统计信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long", paramType = "path")
    })
    @PutMapping(value="obsErvation/{id:\\d+}")
    @RequiresPermissions("collect:obsErvation:update")
    public ResultEntity update(@RequestBody ObsErvation obsErvation, @PathVariable("id") Long id){
        if (StringUtils.isBlank(id)) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_UNSELECTED);
        }
        obsErvation.setId(id);
        if (StringUtils.isBlank(this.obsErvationService.update(obsErvation))) {
            return ResultEntity.fail(ResultStatusEnum.RECORD_REPEAT);
        }
        return ResultEntity.success();
    }
}
